package team.szm.scd.controller;

import org.springframework.web.bind.annotation.*;
import team.szm.scd.database.dto.RequestWrapper;
import team.szm.scd.database.dto.Result;
import team.szm.scd.database.entity.Hospital;
import team.szm.scd.database.vo.WorkVO;
import team.szm.scd.service.interfaces.IHospitalService;
import team.szm.scd.service.interfaces.ILoginService;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/hospital")
public class HospitalController {
    @Resource
    IHospitalService service;
    @Resource
    ILoginService loginService;

    @PostMapping("/id")
    @ResponseBody
    public Result<Hospital> fromId(@RequestBody RequestWrapper<Integer> id, HttpSession session) {
        if (loginService.noUserAndNoDoctorLogin(session)) {
            return Result.needLogin();
        }
        return Result.success(service.fromId(id.value));
    }

    @PostMapping("/search")
    @ResponseBody
    public Result<List<Hospital>>
    searchHospitalWhichNameOrAddressLike(@RequestBody RequestWrapper<String> name, HttpSession session) {
        if (loginService.noUserAndNoDoctorLogin(session)) {
            return Result.needLogin();
        }
        return Result.success(service.nameOrAddressLike(name.value));
    }

    @PostMapping("/dp_work_info")
    @ResponseBody
    public Result<Map<Integer, Map<String, Map<Integer, List<WorkVO>>>>>
        //key1: 科室id, key2: 医生id, key3: 星期
    departmentWorkInfoFromId(@RequestBody RequestWrapper<Integer> id, HttpSession session) {
        if (loginService.noUserAndNoDoctorLogin(session)) {
            return Result.needLogin();
        }
        return Result.success(service.workInfo(id.value));
    }
}
